package com.yang.leather.admin.action.common;

import java.util.ArrayList;
import java.util.List;

import com.yang.leather.admin.pojo.ImgsDel;
import com.yang.leather.common.util.ComUtils;


/**
 * 如果类有表单图片上传功能
 * @author laoliu
 *
 */
public class SimpleUploadAction extends BaseUploadAction{

	private static final long serialVersionUID = 1L;

	public void addUploadType() {}
	
	/**
	 * 更新时，如果保存的图片跟更新前图片不一致，需调用此方法来删除更新前的图片
	 * @param pics  图片路径(filePath+fileName)
	 */
	public void afterUpdAddRemoveFile(String... pics){
		List<ImgsDel> list = new ArrayList<ImgsDel>();
		if(pics!=null && pics.length>0){
			for(String pic : pics){
				String filePath = pic.substring(0,pic.lastIndexOf("/"));
				String fileName = pic.substring(pic.lastIndexOf("/")+1);
				ImgsDel del = new ImgsDel();
				del.setFilePath(filePath);
				del.setFileName(fileName);
				del.setCreateDate(ComUtils.now());
				list.add(del);
			}
		}
		if(list.size()>0){
			imgsDelService.batchSave(list);
		}
	}
}
